<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:zj="http://www.zju.edu.cn" xmlns:y="http://www.zju.edu.cn/ZJ" exclude-result-prefixes="zj y">
  <xsl:import href="TableEditItems_Trans.xslt"/>
  <xsl:template name="y:ProcessHint1">
    <xsl:param name="Field"/>
    <xsl:param name="Pos"/>
    <xsl:param name="IsHidden" select="true()"/>
    <xsl:if test="not($IsHidden) and $Field/zj:Hint">
      <xsl:choose>
        <xsl:when test="string-length($Field/zj:Hint) &lt;= 20">
          <br/>
          <font color="#0000ff" nowrap="nowrap">
            <xsl:value-of select="$Field/zj:Hint"/>
          </font>
        </xsl:when>
        <xsl:otherwise>
          <img src="../images2/icon.jpg" alt="{$Field/zj:Hint}"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
  <xsl:template name="y:ErrorInfo1">
    <xsl:param name="ErrorField"/>
    <xsl:param name="Pos"/>
    <xsl:if test="$ErrorField and $ErrorField/ERROR_POS = $Pos - 1">
      <xsl:attribute name="style">background-color:#ffffcc</xsl:attribute>
      <xsl:attribute name="class">wid80</xsl:attribute>
    </xsl:if>
  </xsl:template>
  <xsl:template name="y:ErrorInfo2">
    <xsl:param name="ErrorField"/>
    <xsl:param name="Pos"/>
    <xsl:if test="$ErrorField and $ErrorField/ERROR_POS = $Pos - 1">
      <img src="../images/ico_alert.GIF" align="absmiddle" width="16" height="16" border="0" style="cursor:help" alt="{$ErrorField/ERROR_VALUE}"/>
    </xsl:if>
  </xsl:template>
  <xsl:template name="y:ProcessAttribute1">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="IsHidden" select="false()"/>
    <xsl:param name="Pos"/>
    <xsl:call-template name="zj:Attribute">
      <xsl:with-param name="Field" select="$Field"/>
    </xsl:call-template>
    <xsl:apply-templates select="$Field" mode="zj:TableAttribute">
      <xsl:with-param name="Value" select="$Value"/>
      <xsl:with-param name="Pos" select="$Pos"/>
      <xsl:with-param name="IsHidden" select="$IsHidden"/>
    </xsl:apply-templates>
  </xsl:template>
  <xsl:template name="zj:Detail1">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <td>
      <xsl:choose>
        <xsl:when test="$Field/zj:Extension/@CheckValue!=''">
          <xsl:if test="$Value=$Field/zj:Extension/@CheckValue">
            <b>
              <IMG src="../images/check.gif" border="0" width="16" height="16"/>
            </b>
          </xsl:if>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="Link" select="$Field/zj:Display/Link"/>
          <xsl:variable name="RefValue" select="../*[local-name()=$Link/@ID]"/>
          <xsl:variable name="HRefAddress">
            <xsl:call-template name="zj:HRefAddress">
              <xsl:with-param name="HRefType" select="$Link/@HRefType"/>
              <xsl:with-param name="Link" select="$Link"/>
              <xsl:with-param name="RefValue" select="$RefValue"/>
              <xsl:with-param name="Value" select="$Value"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="DisplayValue">
            <xsl:call-template name="zj:DisplayValue">
              <xsl:with-param name="Field" select="$Field"/>
              <xsl:with-param name="Value" select="$Value"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:call-template name="zj:DetailValue">
            <xsl:with-param name="HRefType" select="$Link/@HRefType"/>
            <xsl:with-param name="HrefAddress" select="$HRefAddress"/>
            <xsl:with-param name="Value" select="$DisplayValue"/>
            <xsl:with-param name="Target" select="$Link/@Target"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </xsl:template>
  <xsl:template name="zj:Input1">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="Pos"/>
    <xsl:param name="IsHidden"/>
    <xsl:param name="HtmlCtrl"/>
    <xsl:variable name="InputType">
      <xsl:choose>
        <xsl:when test="$HtmlCtrl='EasySearch'">Text</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$HtmlCtrl"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="ErrorNode" select="$zj:Toolkit/ERROR[FIELD_NAME = $Field/zj:FieldName and ERROR_POS = $Pos -1]"/>
    <td>
      <input type="{$InputType}" name="{$Field/zj:FieldName}" id="{$Field/zj:FieldName}" class="wid90">
        <xsl:choose>
          <xsl:when test="$Field/@DataType='Date'">
            <xsl:attribute name="onclick"> gfPop.fPopCalendar(this);return false;</xsl:attribute>
            <xsl:if test="not($IsHidden)">
              <xsl:attribute name="value"><xsl:value-of select="substring($Value, 1, 10)"/></xsl:attribute>
            </xsl:if>
          </xsl:when>
          <xsl:when test="$Field/@DataType='DateTime'">
            <xsl:attribute name="onclick"> gfPop4.fPopCalendar(this);return false;</xsl:attribute>
            <xsl:if test="not($IsHidden)">
              <xsl:attribute name="value"><xsl:value-of select="translate(substring($Value, 1, 19), 'T', ' ')"/></xsl:attribute>
            </xsl:if>
          </xsl:when>
          <xsl:when test="$HtmlCtrl='EasySearch'">
            <xsl:if test="not($IsHidden)">
              <xsl:attribute name="value"><xsl:value-of select="$zj:Toolkit/*[local-name()=$Field/zj:FieldName][CODE_VALUE=$Value]/CODE_NAME"/></xsl:attribute>
            </xsl:if>
          </xsl:when>
          <xsl:when test="$InputType='CheckBox'">
            <xsl:choose>
              <xsl:when test="$IsHidden">
                <xsl:attribute name="value"><xsl:value-of select="$Field/zj:Extension/@CheckValue"/></xsl:attribute>
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="y:CheckBox">
                  <xsl:with-param name="Field" select="$Field"/>
                  <xsl:with-param name="Value" select="$Value"/>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:if test="not($IsHidden)">
              <xsl:attribute name="value"><xsl:call-template name="zj:FormatNumber"><xsl:with-param name="Field" select="$Field"/><xsl:with-param name="Value" select="$Value"/></xsl:call-template></xsl:attribute>
            </xsl:if>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="not($IsHidden)">
          <xsl:call-template name="y:ErrorInfo1">
            <xsl:with-param name="ErrorField" select="$ErrorNode"/>
            <xsl:with-param name="Pos" select="$Pos"/>
          </xsl:call-template>
        </xsl:if>
        <xsl:call-template name="y:ProcessAttribute1">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="IsHidden" select="$IsHidden"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </input>
      <xsl:call-template name="y:ProcessHint1">
        <xsl:with-param name="Field" select="$Field"/>
        <xsl:with-param name="IsHidden" select="$IsHidden"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:call-template>
      <xsl:if test="not($IsHidden)">
        <xsl:call-template name="y:ErrorInfo2">
          <xsl:with-param name="ErrorField" select="$ErrorNode"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:if>
    </td>
  </xsl:template>
  <xsl:template name="zj:Combo1">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="IsHidden"/>
    <xsl:param name="Pos"/>
    <xsl:variable name="ErrorNode" select="$zj:Toolkit/ERROR[FIELD_NAME = $Field/zj:FieldName and ERROR_POS = $Pos -1]"/>
    <td>
      <xsl:variable name="Various" select="$Field/zj:EasySearch/@RegName"/>
      <xsl:variable name="CodeTableName">
        <xsl:choose>
          <xsl:when test="$Various">
            <xsl:value-of select="$Field/zj:FieldName"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$Field/zj:CodeTable"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="CodeTable" select="$zj:Toolkit/*[local-name()=$CodeTableName]"/>
      <select name="{$Field/zj:FieldName}" id="{$Field/zj:FieldName}" size="1">
        <xsl:if test="not($IsHidden)">
          <xsl:call-template name="y:ErrorInfo1">
            <xsl:with-param name="ErrorField" select="$ErrorNode"/>
            <xsl:with-param name="Pos" select="$Pos"/>
          </xsl:call-template>
        </xsl:if>
        <xsl:call-template name="y:ProcessAttribute1">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="IsHidden" select="$IsHidden"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
        <xsl:if test="$Field/zj:IsEmpty = 'true'">
          <option value="-1">
            <xsl:attribute name="selected"/>
            <xsl:value-of select="$Field/zj:Extension/@EmptyTitle"/>
          </option>
        </xsl:if>
        <xsl:for-each select="$CodeTable">
          <option value="{CODE_VALUE}">
            <xsl:if test="CODE_VALUE=$Value">
              <xsl:attribute name="selected"/>
            </xsl:if>
            <xsl:value-of select="CODE_NAME"/>
            <xsl:if test="$Various">
              <xsl:value-of select="concat('(', CODE_VALUE, ')')"/>
            </xsl:if>
          </option>
        </xsl:for-each>
      </select>
      <xsl:call-template name="y:ProcessHint1">
        <xsl:with-param name="Field" select="$Field"/>
        <xsl:with-param name="IsHidden" select="$IsHidden"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:call-template>
      <xsl:if test="not($IsHidden)">
        <xsl:call-template name="y:ErrorInfo2">
          <xsl:with-param name="ErrorField" select="$ErrorNode"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:if>
    </td>
  </xsl:template>
  <xsl:template name="zj:Upload1">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <!-- IsHidden表示是否是新建行 -->
    <xsl:param name="IsHidden"/>
    <xsl:param name="Pos"/>
    <xsl:param name="DataRecord"/>
    <xsl:variable name="ErrorNode" select="$zj:Toolkit/ERROR[FIELD_NAME = $Field/zj:FieldName and ERROR_POS = $Pos -1]"/>
    <xsl:variable name="TableName" select="ancestor::zj:Table/@TableName"/>
    <xsl:variable name="FieldName" select="$Field/zj:FieldName"/>
    <xsl:variable name="Upload" select="$Field/zj:Upload"/>
    <td>
      <input type="text" name="{$FieldName}" id="{$FieldName}" style="width:50%">
        <xsl:if test="not($IsHidden)">
          <xsl:attribute name="value"><xsl:call-template name="zj:FormatNumber"><xsl:with-param name="Field" select="$Field"/><xsl:with-param name="Value" select="$Value"/></xsl:call-template></xsl:attribute>
          <xsl:call-template name="y:ErrorInfo1">
            <xsl:with-param name="ErrorField" select="$ErrorNode"/>
            <xsl:with-param name="Pos" select="$Pos"/>
          </xsl:call-template>
        </xsl:if>
        <xsl:call-template name="y:ProcessAttribute1">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="IsHidden" select="$IsHidden"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
        <xsl:attribute name="onkeyup">if (this.value == '') {var row = GetRowIDEx(this);<xsl:value-of select="$TableName"/>.all('<xsl:value-of select="$Upload/@ServerPathField"/>', row).value='';<xsl:value-of select="$TableName"/>.all('<xsl:value-of select="$Upload/@MimeTypeField"/>', row).value='';<xsl:value-of select="$TableName"/>.all('<xsl:value-of select="$Upload/@SizeField"/>', row).value='';}</xsl:attribute>
      </input>
      <input type="hidden" name="{$Upload/@ServerPathField}" id="{$Upload/@ServerPathField}">
        <xsl:if test="not($IsHidden)">
          <xsl:attribute name="value"><xsl:value-of select="$DataRecord/*[local-name()=$Upload/@ServerPathField]"/></xsl:attribute>
        </xsl:if>
      </input>
      <input type="hidden" name="{$Upload/@MimeTypeField}" id="{$Upload/@MimeTypeField}">
        <xsl:if test="not($IsHidden)">
          <xsl:attribute name="value"><xsl:value-of select="$DataRecord/*[local-name()=$Upload/@MimeTypeField]"/></xsl:attribute>
        </xsl:if>
      </input>
      <input type="hidden" name="{$Upload/@SizeField}" id="{$Upload/@SizeField}">
        <xsl:if test="not($IsHidden)">
          <xsl:attribute name="value"><xsl:value-of select="$DataRecord/*[local-name()=$Upload/@SizeField]"/></xsl:attribute>
        </xsl:if>
      </input>
      <input type="hidden" name="{$FieldName}_TYPERULE" id="{$FieldName}_TYPERULE" value="{$Upload/@FileExt}"/>
      <input type="hidden" name="{$FieldName}_MAXSIZE" id="{$FieldName}_MAXSIZE" value="{$Upload/@MaxSize}"/>
      <input name="{$FieldName}_uploadImg" type="button" class="clsButtonFacebt" onclick="OpenUploadPage({$TableName}.all('{$FieldName}_TYPERULE', GetRowID(this)), {$TableName}.all('{$FieldName}_MAXSIZE', GetRowID(this)), {$TableName}.all('{$FieldName}', GetRowID(this)), {$TableName}.all('{$Upload/@ServerPathField}', GetRowID(this)), {$TableName}.all('{$Upload/@SizeField}', GetRowID(this)), {$TableName}.all('{$Upload/@MimeTypeField}', GetRowID(this)), '{$Upload/@OnUploadedEvent}')" value="浏览..."/>
      <xsl:if test="$Upload/@IsView = 'true'">
        <img src="../images/empty.gif" width="1" height="1"/>
        <img src="../images/lookup.gif" alt="预览" style="border=0;cursor:hand" align="middle" width="18" height="17" name="{$Field/zj:FieldName}_viewImg" onmouseover="ViewUpload({$TableName}.all('{$Upload/@ServerPathField}').value)"/>
      </xsl:if>
      <xsl:call-template name="y:ProcessHint1">
        <xsl:with-param name="Field" select="$Field"/>
        <xsl:with-param name="IsHidden" select="$IsHidden"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:call-template>
      <xsl:if test="not($IsHidden)">
        <xsl:call-template name="y:ErrorInfo2">
          <xsl:with-param name="ErrorField" select="$ErrorNode"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:if>
    </td>
  </xsl:template>
  <xsl:template name="zj:TextArea1">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="Pos"/>
    <xsl:param name="IsHidden"/>
    <xsl:variable name="ErrorNode" select="$zj:Toolkit/ERROR[FIELD_NAME = $Field/zj:FieldName and ERROR_POS = $Pos -1]"/>
    <td>
      <textarea rows="3" name="{$Field/zj:FieldName}" id="{$Field/zj:FieldName}" class="wid90">
        <xsl:if test="not($IsHidden)">
          <xsl:call-template name="zj:FormatNumber">
            <xsl:with-param name="Field" select="$Field"/>
            <xsl:with-param name="Value" select="$Value"/>
          </xsl:call-template>
        </xsl:if>
        <xsl:if test="not($IsHidden)">
          <xsl:call-template name="y:ErrorInfo1">
            <xsl:with-param name="ErrorField" select="$ErrorNode"/>
            <xsl:with-param name="Pos" select="$Pos"/>
          </xsl:call-template>
        </xsl:if>
        <xsl:call-template name="y:ProcessAttribute1">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="IsHidden" select="$IsHidden"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </textarea>
      <xsl:call-template name="y:ProcessHint1">
        <xsl:with-param name="Field" select="$Field"/>
        <xsl:with-param name="IsHidden" select="$IsHidden"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:call-template>
      <xsl:if test="not($IsHidden)">
        <xsl:call-template name="y:ErrorInfo2">
          <xsl:with-param name="ErrorField" select="$ErrorNode"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:if>
    </td>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:TableAttribute">
    <xsl:param name="Value"/>
    <xsl:param name="IsHidden" select="false()"/>
    <xsl:param name="Pos"/>
  </xsl:template>
</xsl:stylesheet>
